package com.algorithm;

import java.util.Arrays;
import java.util.Vector;

/**
 * describe:
 *
 * @author wangfeixiong
 * @date 2018/03/19
 */
public class ArrayShort {


    public static final int[] insertionSort(int[] array) {
        for (int out = 1; out < array.length; out++) {
            for (int in = out; array[in - 1] > array[out]; in--) {
                array[in] = array[in - 1];
                array[in] = array[out];
            }
        }
        return array;
    }

    public static final int[] selectSort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = i; j < array.length; j++) {
                if (array[i] > array[j]) {
                    array[i] = array[i] + array[j];
                    array[j] = array[i] - array[j];
                    array[i] = array[i] - array[j];
                }
            }
        }
        return array;
    }

    public static final int[] bubbleSort(int[] array) {
        for (int i = array.length; i >= 0; i--) {
            for (int j = 1; j < i; j++) {
                if (array[j - 1] < array[j]) {
                    array[j] = array[j] + array[j - 1];
                    array[j - 1] = array[j] - array[j - 1];
                    array[j] = array[j] - array[j - 1];
                }
            }
        }
        return array;
    }


}